package com.ppp.poi.web;

import com.ppp.poi.bean.base.AppResult;
import com.ppp.poi.bean.entity.User;
import com.ppp.poi.bean.enumeration.RES_STATUS;
import com.ppp.poi.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Wu Jin
 * @create 2020-01-20
 */
@Slf4j
@RequestMapping("/user")
@RestController
public class UserController {

  @Autowired
  private UserService userService;

  /**
   * 保存用户
   */
  @PostMapping("/save")
  public AppResult save(User user) {
    log.info("保存用户：user={}", user);
    if (user.getId() == null || user.getId() == 0) {
      userService.insert(user);
    } else {
      userService.update(user);
    }
    return new AppResult(RES_STATUS.SUCCESS);
  }

}
